def is_prime(number):
  if number <= 1:
    return False
  for i in range(2, int(number*0.5) + 1):
    if number % i == 0:
      return False
  return True

def find_nearest_prime(number_words):
  number_words_to_digits = {
      "zero": "0",
      "one": "1",
      "two": "2",
      "three": "3",
      "four": "4",
      "five": "5",
      "six": "6",
      "seven": "7",
      "eight": "8",
      "nine": "9",
  }
  number_str = "".join(number_words_to_digits.get(word, "") for word in number_words)
  if not number_str.isdigit() or len(number_str) != 3:
    return "Wrong input"
  number = int(number_str)
  lower_number = number - 1
  upper_number = number + 1
  while True:
    if is_prime(lower_number):
      return lower_number
    elif is_prime(upper_number):
      return upper_number
    else:
      lower_number -= 1
      upper_number += 1
input_words = input().split()
result = find_nearest_prime(input_words)
print(result)
